package com.blkbox.javaee.quartz.version2_0;

import java.util.ArrayList;
import java.util.Date;

import org.quartz.JobBuilder;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

public class SimpleTriggerTest {

	public static void main(String[] args) throws SchedulerException {
		// 0. Initiate a Schedule Factory
		SchedulerFactory schedulerFactory = new StdSchedulerFactory();
		Scheduler scheduler = schedulerFactory.getScheduler();
		// start time
		long ctime = System.currentTimeMillis();
		// 1. prepare job
		JobDataMap dataMap = new JobDataMap();
		dataMap.put("name", "ZJ");
		dataMap.put("password", "1pa@wd");
		dataMap.put("date", new Date());
		dataMap.put("list", new ArrayList<String>());
		JobDetail jobDetail = JobBuilder.newJob(SimpleQuartzJob.class).withIdentity("jobName-1", "jobNameGroup-1").usingJobData(dataMap).build();
		// 2. prepare trigger
		Trigger simpleTrigger = TriggerBuilder.newTrigger().withIdentity("simpleTriggerName-1", "simpleTriggerGroup-1")
				.withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(5).withRepeatCount(10)).startNow().endAt(new Date(ctime + 60000L)).build();
		// 3. start the scheduler
		scheduler.scheduleJob(jobDetail, simpleTrigger);
		// 4. start the scheduler
		scheduler.start();
	}

}
